package com.algorithm.basic;/*
 *@Author:DOWN
 *@Date:2021/12/11 10:30
 *@Comment:线性查询
 */

import com.algorithm.entitys.Student;
import com.algorithm.testutils.ArrayGenerator;
public class LinearSearch {
    public static void main(String[] args){
        intTest();
    }
    private static void intTest(){
        long start=System.nanoTime();
        System.out.println("start:"+start);
        int n=100000000;
        search(ArrayGenerator.getArrays(n),n);
        long end=System.nanoTime();
        System.out.println("end:"+end);
        System.out.println("over:"+((end-start)/1000000000.0)+"s");
    }
    private static void objectTest(){
        Student one=new Student("aaa");
        Student two=new Student("bbb");
        Student three=new Student("ccc");
        Student four=new Student("ccc");
        Student[] students={one,two,three};
        int rel=search(students,four);
    }
    public static <e> int search(e[] data, e target) {
        int index=0;
        for (e item : data) {
            if(item.equals(target)) {
                return index;
            }
            index++;
        }
        return -1;
    }
}
